package com.elnguage.lox;
import java.util.List;

import com.elnguage.lox.BaseStmt.StellaStmt;
import com.elnguage.lox.Expr.Literal;
import com.elnguage.lox.Stmt.Var;

public class StellaEvent implements LoxCallable
{

    private final StellarisStmt.Event event;

    StellaEvent(StellarisStmt.Event event)
    {
        this.event = event;
    }

    @Override
    public String toString()
    {
        return "<stella_event " + event.name.lexeme + ">";
    }

    @Override
    public int arity() {
        return 0;
    }

    private Expr GetDomainName()
    {
        try{
            for (var x : event.body) 
            {
                assert x instanceof Var;
                Var varx = (Var) x;
                String x_name = varx.name.lexeme;
                if(x_name == "domain")
                {
                    assert varx.initializer.toString() == "global" || x_name == "country" || x_name == "planet";
                    return varx.initializer;
                }
            }
            throw new Exception(String.format("StellaEvent %s has no field or incorrect field of domain", event.name.lexeme)); 
        }
        catch(Exception exception)
        {
            System.err.println(exception);
            return null;
        }
    }

    @Override
    public Object call(Interpreter interpreter, List<Object> arguments) {
        // Expr domain_expr = GetDomainName();
        // assert domain_expr instanceof Literal;
        // var domain_eval = interpreter.visitLiteralExpr((Literal)domain_expr);
        // String domain = (String)domain_eval;
        interpreter.executeBlock(event.body, interpreter.GetCurrentEnv());
        return null;
    }
    
}
